//
//  A_addWLCell.m
//  Estate
//
//  Created by heyong on 16/6/17.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "A_addWLCell.h"
#import "C_addWLCell_1.h"
#import "C_addWLCell_2.h"
#import "B_SwitchCell.h"
#import "QianDTableCell.h"

@implementation A_addWLCell

- (UITableView *)tableView{
    if(_tableView==nil){
        _tableView=[[UITableView alloc]initWithFrame:CGRECTS(0, 46,375,280)];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.bounces=NO;
        [_tableView registerNib:[UINib nibWithNibName:@"C_addWLCell_1" bundle:nil] forCellReuseIdentifier:@"cell1"];
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        [_tableView  registerNib:[UINib nibWithNibName:@"C_addWLCell_2" bundle:nil] forCellReuseIdentifier:@"cell2"];
        [_tableView registerNib:[UINib nibWithNibName:@"B_SwitchCell" bundle:nil] forCellReuseIdentifier:@"switch"];
        [_tableView registerNib:[UINib nibWithNibName:@"QianDTableCell" bundle:nil] forCellReuseIdentifier:@"qian"];
    }
    return _tableView;
}

-(UIView *)topView{
    if(_topView==nil){
        _topView=[[UIView alloc]initWithFrame:CGRECTS(0, 0, 375, 46)];
        _topView.backgroundColor=[UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1.00];
    }
    return _topView;
}
- (UILabel *)titLab{
    if(_titLab==nil){
        _titLab=[[UILabel alloc]init];
        _titLab.font=[UIFont systemFontOfSize:15.];
    }
    return _titLab;
}
- (UIButton *)dleBtn{
    if(_dleBtn==nil){
        _dleBtn=[[UIButton alloc]init];
    }
    return _dleBtn;
}
- (void)setSite:(Site_03_01 *)site{
    _site=site;
    //赋值的同时，刷新cell内部tableView
    [self.tableView reloadData];
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self cteateView];
        self.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    
    return self;
}


//!!!:创建视图
- (void)cteateView{
    [self.contentView addSubview:self.topView];
    //颜色条
    UIView *line=[[UIView alloc]init];
    [self.topView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(0);
        make.top.mas_offset(0);
        make.bottom.mas_offset(0);
        make.width.offset(4);
    }];
    line.backgroundColor=[UIColor colorWithRed:0.07 green:0.53 blue:0.49 alpha:1.00];
    
    //文字
    [self.topView addSubview:self.titLab];
    [self.titLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(line.mas_right).mas_offset(10);
        make.width.mas_offset(60);
        make.height.mas_offset(40);
    }];
    
    //移除按钮
    [self.topView addSubview:self.dleBtn];
    [self.dleBtn setImage:[UIImage imageNamed:@"quxiao"] forState:UIControlStateNormal];
    [self.dleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.right.mas_offset(-10);
        make.width.offset(30);
        make.height.offset(30);
    }];
    [self.dleBtn addTarget:self action:@selector(dleAction) forControlEvents:UIControlEventTouchUpInside];
    
    //添加表格
    [self.contentView addSubview:self.tableView];
    
}
#pragma mark-methold
- (void)dleAction{
    if(self.deleteBlock){
        self.deleteBlock();
    }
}


#pragma mark-UITaleViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row==3){
        return 100*BIZ;
    }else{
        return 44*BIZ;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    long row=indexPath.row;
    if(row==0){
        
        C_addWLCell_1 *cell=[tableView dequeueReusableCellWithIdentifier:@"cell1"];
    
        //填筑步数
        cell.text1ValueChangedBlock=^(NSString *valuer){
              self.text1Block(valuer);
        };
        //虚铺厚度
        cell.text2ValueChangedBlock=^(NSString *valuer){
            self.text2Block(valuer);
        };
        
        //设置数据
        [cell setValues:_site.tzbs AndValuer2:_site.xphd];
        
        return cell;
        
    }else if (row==1){
        //压实厚度
        QianDTableCell *cell=[tableView dequeueReusableCellWithIdentifier:@"qian"];
        
        cell.textValueChangedBlock=^(NSString *valuer){
            self.text3Block(valuer);
        };
        
        [cell configWithPlaceholder:@"请输入数字" andValue:_site.yshd andLabel:@"压实厚度(cm)" andKeyType:UIKeyboardTypeDefault];
        
        return cell;
        
    }else if(row==2){
        //环刀取样数量及编号
        QianDTableCell *cell=[tableView dequeueReusableCellWithIdentifier:@"qian"];
        
        
        cell.textValueChangedBlock=^(NSString  *valuer){
            self.text4Block(valuer);
        };

        [cell configWithPlaceholder:@"请输入数字" andValue:_site.hdqy andLabel:@"环刀取样数量及编号" andKeyType:UIKeyboardTypeDefault];
        
        return cell;
    }else if (row==3){
        C_addWLCell_2 *cell=[tableView dequeueReusableCellWithIdentifier:@"cell2"];
        
        //含水量
        cell.text1ChangeBlock=^(NSString *valuer){
            self.text5Block(valuer);
            
        };
        //干密度
        cell.text2ChangeBlock=^(NSString *valuer){
            self.text6Block(valuer);

        };
        //压实度
        cell.text3ChangeBlock=^(NSString *valuer){
            self.text7Block(valuer);
            
        };
        
        [cell setText1:_site.hsl andText2:_site.gmd andText3:_site.ysd];
        
        return cell;
        
    }else {
        B_SwitchCell *cell=[tableView dequeueReusableCellWithIdentifier:@"switch" ];
        cell.title.font=[UIFont systemFontOfSize:16*BIZ];
        cell.sValueChangeBlock=^(UISwitch *sender){
            self.text8Block(sender);
        };
        
        return cell;
    }
}

/*
 *  此方法让cell横线置顶
 */
-(void)viewDidLayoutSubviews {
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
        
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}


@end
